/*
 * Zaohuipassword.java
 *
 * Created on __DATE__, __TIME__
 */

package WindowsModule;

/**
 * 
 * @author __USER__
 */
import java.awt.event.MouseListener;

import javax.swing.JOptionPane;

import Client.ClientListener;
import Client.MsgEvent;
import Server.UserDBHandle;
import Tools.IMG;
import Tools.ToCenter;
import Windows.MainWindows;
import Windows.PicPanel;

public class Zaohuipassword extends javax.swing.JFrame implements ClientListener {

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				new Zaohuipassword().setVisible(true);
			}
		});
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;

	// GEN-END:initComponents

	private javax.swing.JLabel jLabel1;

	private javax.swing.JLabel jLabel2;

	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel6;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPasswordField jPasswordField1;
	private javax.swing.JPasswordField jPasswordField2;
	private javax.swing.JTextField jTextField1;
	private javax.swing.JTextField jTextField2;
	private javax.swing.JTextField jTextField3;
	/** Creates new form Zaohuipassword */
	public Zaohuipassword() {

		setContentPane(new PicPanel(IMG.DownBG));
		jPanel1 = new PicPanel("", "Skin/speed3.JPG");

		initComponents();
		MainWindows.getInstance().client.addClientListenser(this);

		MouseListener ml = ((PicPanel) jPanel1).getMouseListener();
		jLabel2.addMouseListener(ml);
		jLabel3.addMouseListener(ml);
		jLabel4.addMouseListener(ml);
		jLabel5.addMouseListener(ml);
		jLabel6.addMouseListener(ml);
		jTextField1.addMouseListener(ml);
		jTextField2.addMouseListener(ml);
		jTextField3.addMouseListener(ml);
		jPasswordField1.addMouseListener(ml);
		jPasswordField2.addMouseListener(ml);
		ToCenter.ToCenter(this);
	}
	@Override
	public void dispose() {
		MainWindows.getInstance().client.removeClientListenser(this);
		super.dispose();
	}
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel2 = new javax.swing.JLabel();
		jTextField1 = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jTextField2 = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		jTextField3 = new javax.swing.JTextField();
		jLabel5 = new javax.swing.JLabel();
		jPasswordField1 = new javax.swing.JPasswordField();
		jLabel6 = new javax.swing.JLabel();
		jPasswordField2 = new javax.swing.JPasswordField();
		jLabel1 = new javax.swing.JLabel();
		jButton1 = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("\u627e\u56de\u5bc6\u7801");

		jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("宋体", 0, 12), new java.awt.Color(1, 2, 3)));

		jLabel2.setText("\u5bc6\u7801\u63d0\u95ee\uff1a");

		jLabel3.setText("\u5bc6\u7801\u7b54\u6848\uff1a");

		jLabel4.setText("\u7528\u6237\u540d\uff1a");

		jLabel5.setText("\u8f93\u5165\u65b0\u5bc6\u7801\uff1a");

		jLabel6.setText("\u786e\u8ba4\u65b0\u5bc6\u7801\uff1a");

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				jPanel1Layout.createSequentialGroup().addGap(20, 20, 20).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE).addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addComponent(jPasswordField2, javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)).addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap()));
		jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4).addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(8, 8, 8)
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel6).addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(20, Short.MAX_VALUE)));

		jLabel1.setFont(new java.awt.Font("YouYuan", 3, 14));
		jLabel1.setText("\u627e\u56de\u5bc6\u7801");

		jButton1.setText("\u786e\u5b9a");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		String id = jTextField3.getText();
		String Tiwen = jTextField1.getText();
		String daan = jTextField2.getText();
		String pass1 = jPasswordField1.getText();
		String pass2 = jPasswordField2.getText();
		if (id.equals("") && Tiwen.equals("") && daan.equals("") && pass1.equals("") && pass2.equals("")) {
			JOptionPane.showMessageDialog(null, "必须填写完整各项信息");

		} else {
			if (pass1.equals(pass2)) {
				StringBuffer sb = new StringBuffer("<zhmm ");
				sb.append("userid=\"").append(id).append("\" ");
				sb.append("tiwen=\"").append(Tiwen).append("\" ");
				sb.append("daan=\"").append(daan).append("\" ");
				sb.append("pwd=\"").append(pass2).append("\" ");
				sb.append(" />");

				MainWindows.getInstance().client.send(sb);

				jButton1.setEnabled(false);
			} else {
				JOptionPane.showMessageDialog(null, "密码不一致");
			}
		}

	}

	@Override
	public void onCloseEvent(Client.CloseEvent cce) {
		// TODO Auto-generated method stub

	}

	// End of variables declaration//GEN-END:variables
	@Override
	public void onMsgEvent(MsgEvent ce) {
		if (ce.getCmd().FLAG.equals("zhmm")) {
			jButton1.setEnabled(true);
			if (ce.getCmd().get("value").equals("true")) {
				JOptionPane.showMessageDialog(null, "新密码设置成功！");
				this.dispose();
			} else {
				JOptionPane.showMessageDialog(null, "原始信息不正确");
			}
		}
	}
}